package com.yeswater.multithread.chapter7;

/**
 * author： yeswater
 * create： 2023/11/8
 *
 * 线程组中的一个线程出现异常后，不会影响其他线程的运行
 */
public class Run_7_8_1 {
    public static void main(String[] args) {
        ThreadGroup group = new ThreadGroup("my-thread-group");
        Thread1[] thread1s = new Thread1[10];
        
        Thread1 newT = new Thread1(group, "报错线程", "a");
        newT.start();
        
        for (int i = 0; i < thread1s.length; i++) {
            thread1s[i] = new Thread1(group, "线程" + (i + 1), "1");
            thread1s[i].start();
        }
    }
    
    private static class Thread1 extends Thread {
        private String num;
        
        public Thread1(ThreadGroup group, String name, String num) {
            super(group, name);
            this.num = num;
        }
        
        @Override
        public void run() {
            int numInt = Integer.parseInt(num);
            while (true) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("死循环中：" + Thread.currentThread().getName());
            }
        }
    }
}
